package org.jactao.remote.netty;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import org.apache.commons.beanutils.BeanUtils;
import org.jactao.common.LRequest;
import org.jactao.rpc.LRequestPool;

/**
 * Created by fanzetao on 2018/4/3.
 */
@ChannelHandler.Sharable
public class NettyServerHandler extends SimpleChannelInboundHandler<LRequest> {

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
    }

    @Override
    public void channelRead0(ChannelHandlerContext ctx, LRequest msg) throws Exception {
        LRequest request = new LRequest();
        BeanUtils.copyProperties(request, msg);
        LRequestPool.publishEvent(request, ctx.channel());
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    }

}
